package com.atcper

/**
 * @author : ranzlupup
 * @date : 2023/2/23 20:15
 */
object Scala12_Collection_Array {

    def main(args: Array[String]): Unit = {

        //        String[] str = new String[3];
        val strings = new Array[String](3)
        strings(0) = "tom0"
        strings(1) = "tom1"
        strings(2) = "tom2"
        println(strings)
        println(strings.mkString(","))
        println("*************************")

        for (elem <- strings) {
            println(elem)
        }
        println("*************************")

        // 采用面向对象的方式实现循环操作
        def forEachFunction(str: String) = {
            println("===========" + str)
        }

        strings.foreach(forEachFunction)
        println("*************************")

        strings.foreach((str: String) => println("===========" + str))
        println("*************************")
        strings.foreach(str => println("===========" + str))
        println("*************************")
        strings.foreach(println(_))
        println("*************************")
        val ints: Array[Int] = Array.apply(1, 2, 3, 4)
        val ints1: Array[Int] = Array(1, 2, 3, 4)
        ints.foreach(println)
        println("*************************")
        val ints2 = ints :+ 6
        ints2.foreach(println)
        println("*************************")
        val ints3 = 5 +: ints
        ints3.foreach(println)

    }
}
